package com.lanou.lenanapp.volley;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.android.volley.toolbox.ImageLoader;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 */
public class DiskCache implements  ImageLoader.ImageCache{

        static String cacheDir = "sdcard/cache/";

        @Override
        public Bitmap getBitmap(String url) {
            return BitmapFactory.decodeFile(cacheDir + url);
        }

        @Override
        public void putBitmap(String url, Bitmap bitmap) {
            FileOutputStream fileOutputStream = null;
            try {
                fileOutputStream = new FileOutputStream(cacheDir + url);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }


